<script type="text/javascript" language="javascript">
    function edit_validate(){
 
        var news_title = document.getElementById('news_title').value;
        var news_content = tinyMCE.get('news_content').getContent();
        var news_image = document.getElementById('news_image').value;
        var countError = 0;
        if((news_title.length < 1) || (news_title.length > 300)){
            document.getElementById('errorNewsTitle').innerHTML = 'Tiêu đề không quá 150 ký tự';
            countError++;
        }
        else
        {
            document.getElementById('errorNewsTitle').innerHTML = '';
        }
        
        if((news_content.length < 50) || (news_content.length > 5000)){
            
            document.getElementById('errorNewsContent').innerHTML = 'Nội dung không quá 5000 ký tự và không ít hơn 50 ký tự';
            countError++;
        }
        else{
            document.getElementById('errorNewsContent').innerHTML = '';
        }
        
        if(countError > 0)
        {
            return false;
        }
        else
        {
            content = tinyMCE.get('news_content').getContent({format : 'raw'});
            re = /<[a-zA-Z\/][^>]*>/ig;
            content = content.replace(re," ");
            re = /&\w+;/ig;
            content = content.replace(re," ");   
            content = content.replace(/\s{2,}/," ");
            //Luu gia tri plain text vao truong an. Sau khi submit ve server, lay gia tri
            //truong an ra de luu vao mot truong du lieu ban ro cua noi dung, phuc vu tim kiem
            
            document.getElementById('news_plaintext').value = content;
            return true;
        }
        
    }
</script>

<div class="heading">
    <div class="left_heading"></div>
                                
    <div class="content_heading">
        <h3>Sửa tin tức</h3>
    </div>
                                
    <div class="right_heading"></div>
</div><!-- End .heading -->

<div class="main_content">
    <form name="myform" action="" enctype="multipart/form-data" method="post" onsubmit="return edit_validate()">  
        <input type="hidden" name="news_plaintext" id="news_plaintext" />    
        <table class="table_content">
			<tr >
                <td class="label"><label for="news_title">Tiêu đề</label><span class="msg"> * </span></td>
				<td class="label2"><?php echo $this->formText('news_title', $this->data['news_title'], array('id' => 'news_title','class' => 'input' )); ?></td>
                <td><span class="msg" id="errorNewsTitle"><?php echo $this->errorNewsTitle; ?></span></td>
            </tr>
            <tr >
                <td class="label"><label for="news_image">Ảnh</label><span class="msg"> * </span></td>
                <td class="label2"><?php echo $this->formFile('news_image', array('id' =>'news_image' )); ?></td>
                <td><span class="msg" id="errorImage"><?php echo $this->errorImage; ?></span></td>
            </tr>
            <tr >
                <td class="label"><label for="news_content">Nội dung</label><span class="msg"> * </span></td>
				<td class="label2"><span><?php echo $this->formTextarea('news_content', $this->data['news_content'], array('id' => 'news_content',)); ?></span></td>
                <td><span class="msg" id="errorNewsContent"><?php echo $this->errorNewsContent; ?></span></td>
            </tr>
            
            <tr >
                <td class="label"><label for="create_date">Ngày tạo</label><span class="msg"> * </span></td>
			    <td class="label2"><?php echo $this->formText('create_date', $this->data['create_date'], array('id' => 'create_date', 'class' => 'input')); ?></td>
            </tr>
            <tr>
                <td class="label"><?php echo $this->formLabel('status','Status',array('class'=>'label')) ;?><span class="msg"> * </span></td>
                <td >
                    <?php
                    echo $this->formSelect('status',$this->data['status'],array('id'=>'status','class'=>'input'),array('1'=>'Hiển thị','0'=>'Ẩn đi'));
                    ?>
                </td>
            </tr>
            <tr>
				<td class="label3">&nbsp;</td>
				<td colspan="2">&nbsp;</td>
	      	</tr>
            <tr>
           	     <td class="label3"></td>
			     <td><input class="button" type="submit" name="submit" value="Cập nhật"/>
		             <input class="button" type="reset" name="reset" value="Nhập lại"/>
				     <a href="<?php echo $this->baseUrl('admin/news'); ?>" class="button" style="padding-top: 7px;">Quay lại</a>
                 </td>
            </tr>
        </table>
    </form>
</div><!-- End .main_content -->  